﻿using Abp.Dependency;
using Abp.Domain.Uow;
using Abp.RemoteEventBus;
using Abp.Runtime.Caching;
using FwProject.Core.Distribution;
using System;
using System.Collections.Generic;
using System.Text;
using Abp.Domain.Repositories;
using FwProject.Core.AppVersion;
using FwProject.Core.Car;
using FwProject.Car;
using FwProject.Core.FactoryInfo;
using FwProject.Core.Restaurant;
using FwProject.Core.SettlementInfoModel;
using FwProject.Core.TypeNumber;
using Castle.Core.Logging;
using Abp.ObjectMapping;
using Abp.ElasticSearch;
using FwProject.BrandInfo;
using System.Threading.Tasks;
using FwProject.BrandInfo.Dto;
using FwProject.ShoppingMall.Shop;
using FwProject.Shop.Dto;
using FwProject.Shop;
using FwProject.Keyword.Dto;
using FwProject.Keyword;
using FwProject.ShoppingMall.Com;
using System.Linq;
using FwProject.Manager;
using FwProject.Comm;

namespace FwProject.ShopApplication.RemoteEventBus
{
    /// <summary>
    ///餐厅缓存数据
    /// </summary>
    [RemoteEventHandler(ForType = RemoteTypeHelp.TYPEREMOVETYPEBYPRODUCT, ForTopic = RemoteTypeHelp.TOPICAPPPRODUCT)]
    public class RemoteEventBusDeleteTypeAndProduct : IRemoteEventHandler, ITransientDependency
    {
        public ICacheManager _catchmanager { get; set; }
        public IElasticsearch _elasticsearch;
        private readonly IRepository<ShopProduct, Guid> _repositoryShopProduct;//具体商品
        public ILogger iLogger { get; set; }

        public IObjectMapper _objectMapper { get; set; }
        public IShopTypeAppService _shopTypeAppService;
        public RemoteEventBusDeleteTypeAndProduct(
                IElasticsearch elasticsearch,
              IRepository<ShopProduct, Guid> repositoryShopProduct
            )
        {
            _repositoryShopProduct = repositoryShopProduct;
             _objectMapper = NullObjectMapper.Instance;
            _elasticsearch = elasticsearch;
   
        }
        [UnitOfWork]
        public void HandleEvent(RemoteEventArgs eventArgs)
        {
            Guid id = Guid.Parse(eventArgs.EventData.Data[RemoteTypeHelp.MODELID].ToString());
            iLogger.Info($"清空商品==={eventArgs.EventData.Data[RemoteTypeHelp.MODELID].ToString()}===清空商品");
            iLogger.Info($"清空商品==={eventArgs.EventData.Data[RemoteTypeHelp.MODELNAME].ToString()}===清空商品");
            try
            {
                var list = _repositoryShopProduct.GetAll().Where(o => o.ShopTypeid == id);
           
                 foreach (var item in list)
                 {
                    //Task.Run(()=>_shopCarManager.DeleteShopCar(item));
                    item.IsGrounding = false;
                 }
            }
            catch (Exception exe)
            {
                iLogger.Error($"清空商品==={eventArgs.EventData.Data[RemoteTypeHelp.MODELNAME].ToString()}===清空商品", exe);
            }
        }
    }
}
